package ext.sim.forces;

import ext.sim.Body;
import java.util.ArrayList;
import static math.vec3.*;
import math.vec3;

public class ForceViscousDrag implements Force
{
    
    private ArrayList<Body> rBodies;
    
    private double mLinearDamp;
    
    private double mAngularDamp;
    
    
    public ForceViscousDrag(
            ArrayList<Body> aBodies, 
            double aLinearDamp, 
            double aAngularDamp)
    {
        this.rBodies = aBodies;
        this.mLinearDamp = aLinearDamp;
        this.mAngularDamp = aAngularDamp;
    }
    
    
    public void apply()
    {
        for (Body b : this.rBodies)
        {
            vec3 fLinear = mul(-b.mMass * this.mLinearDamp, b.mV);
            
            vec3 tAngular = b.mI.mul(b.mW);
            tAngular.mul(-this.mAngularDamp);
            
            b.mF.add(fLinear);
            b.mT.add(tAngular);
        }
    }
    
}
